package com.example.gw_back_end.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gw_back_end.domain.PageParam;
import com.example.gw_back_end.domain.PageResult;
import com.example.gw_back_end.domain.entities.Section;
import com.example.gw_back_end.mapper.SectionMapper;
import com.example.gw_back_end.service.SectionService;
import org.springframework.stereotype.Service;

@Service
public class SectionServiceImpl extends ServiceImpl<SectionMapper, Section> implements SectionService {

    private final SectionMapper sectionMapper;
    public SectionServiceImpl(SectionMapper sectionMapper) {
        this.sectionMapper = sectionMapper;
    }

    // 新增板块
    @Override
    public boolean addSection(Section section) {
        return sectionMapper.insert(section) > 0;
    }

    // 删除板块
    @Override
    public boolean deleteSection(Integer id) {
        return sectionMapper.deleteById(id) > 0;
    }

    // 获取板块
    @Override
    public Section getSectionById(Integer id) {
        return sectionMapper.selectById(id);
    }

    // 获取板块列表
    @Override
    public PageResult<Section> getSectionByPage(PageParam pageParam) {
        Page<Section> sectionPage = new Page<>(pageParam.getPage(), pageParam.getSize());
        return PageResult.setPageResult(sectionPage);
    }

    // 更新板块
    @Override
    public boolean updateSection(Section section) {
        return sectionMapper.updateById(section) > 0;
    }
}
